package cn.itrip.auth.service;

import cn.itrip.common.RedisUtils;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 发送邮箱类
 */
@Service
public class EmailServiceImpl implements EmailService {

    @Resource
    private MailSender mailSender;
    @Resource
    private SimpleMailMessage simpleMailMessage;
    @Resource
    private RedisUtils redisUtils;


    @Override
    public void send(String userCode, String md5) throws Exception {
        //邮件接收
        simpleMailMessage.setTo(userCode);
        //邮件内容
        simpleMailMessage.setText("注册邮箱"+userCode+"激活码"+md5);
        //发送邮件
        mailSender.send(simpleMailMessage);
        //把激活码保存到redis中
        redisUtils.setValueExpire("md5"+userCode,md5,30*60);
    }
}
